package com.project.service;

import com.project.dao.PositionTypeMapper;
import com.project.entity.PositionType;
import com.project.service.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: TateBrown
 * @date: 2018/5/26 14:52
 * @param:
 * @return:
 */
@Transactional(rollbackFor=Exception.class)
@Service
public class PositionTypeServiceImpl extends BaseService implements PositionTypeService {
    @Autowired
    private  PositionTypeMapper positionTypeMapper;
    @Override
    public PositionType findById(int id) {
        return positionTypeMapper.selectByPrimaryKey(id);
    }

    @Override
    public int update(PositionType positionType) {
        return positionTypeMapper.updateByPrimaryKeySelective(positionType);
    }

    @Override
    public int addOne(PositionType positionType) {
        return positionTypeMapper.insertSelective(positionType);
    }

    @Override
    public int delete(int id) {
        return positionTypeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<PositionType> findAll() {
        return positionTypeMapper.selectAll();
    }

    /**
     * author: WheelChen
     * date: 2017/8/2
     * function: 根据学院id批量查找岗位
     *
     * @param schoolId 学院id
     * @return
     */
    @Override
    public List<PositionType> findBatchBySchoolId(Integer schoolId) {
        return positionTypeMapper.selectBatchBySchoolId(schoolId);
    }

    /**
     * author: WheelChen
     * date: 2017/8/9
     * function: [条件]查找岗位类别
     *
     * @param positionType
     * @return
     */
    @Override
    public List<PositionType> findBatchByCondition(PositionType positionType) {
        return positionTypeMapper.selectBatchByCondition(positionType);
    }

    /**
     * author: WheelChen
     * date: 2017/10/16
     * function: 检查当前岗位是否已存在
     *
     * @param typename 岗位名称
     * @param schoolid 学院id
     * @return true-存在 false-不存在
     */
    @Override
    public boolean checkTypenameIsExist(String typename, Integer schoolid) {
        return positionTypeMapper.checkTypeNameAndSchoolidIsExist(typename, schoolid) != 0;
    }
}
